<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Settlement extends Model
{
    //
	protected $table='settlement';
//	protected $fillable=[
//		'period','store_id','store_name','start_time','end_time','create_uid'
//		,'create_name','status','sum_hour','sum_money','company_id',
//		'should_hour','actual_hour','owner_name','reward'
//	];
	protected $guarded=[];
	protected $hidden=[];


	public function lists($where){

		$data=$this->where(function ($query) use($where){
			$query->where(['company_id'=>$where['company_id']]);

			if($where['period'] !=null){
				$query->where(['period'=>$where['period']]);
			}
			if($where['start_time'] !=null){
				$query->where('created_at','>',$where['start_time']);
			}
			if($where['start_time'] !=null){
				$query->where('created_at','<',$where['end_time']);
			}
			if($where['statu'] !=null){
				$query->where('statu','=',$where['statu']);
			}
			if($where['status'] !=null){
				$query->where('status','=',$where['status']);
			}
		})->simplePaginate(config('app.config'));
//		foreach($data as $kk=>$vv){
//			if($data[$kk]['status']==1){
//				$data[$kk]['account']='未结算';
//			}
//			if($data[$kk]['status']==2){
//				$data[$kk]['account']='结算中';
//			}
//			if($data[$kk]['status']==3){
//				$data[$kk]['account']='分配奖金中';
//			}
//			if($data[$kk]['status']==4){
//				$data[$kk]['account']='已结算';
//			}
//		}
//		$newArr=[];
//		foreach($data as $k=>$v){
//			if($v['statu'] ==2){
//				$newArr['distribution'][]=$v;
//			}
//			if($v['statu'] ==1){
//				$newArr['no_distribution'][]=$v;
//			}
//			$newArr['all'][]=$v;
//		}
		return $data;
	}



	public function reward_list($store_id){
		$month=date("Y-m",time());
		return $this->where(['store_id'=>$store_id,'period'=>$month])
			->with('settle_desc')
			->first();
	}

	public function settle_desc(){
		return $this->hasMany('App\Model\Settle_desc','settle_id');
	}




	public function store(){
		return $this->belongsTo('App\Model\Store','store_id');
	}



}
